﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace NGUYENTHUTRANG
{
    public partial class frmifelse : Form
    {
        public frmifelse()
        {
            InitializeComponent();
        }

        private void btntinhtoan_Click(object sender, EventArgs e)
        {
            
            if(txtnhapa.Text=="")
            {
                MessageBox.Show("Bạn chưa nhập a");
            }
            else
            {
                if(txtnhapb.Text=="")
                {
                    MessageBox.Show("Bạn chưa nhập b");
                }
                else
                {
                    if(comboBox1.Text=="")
                    {
                        MessageBox.Show("Bạn chưa chọn phép tính");

                    }
                    else
                    {
                        if(comboBox1.Text=="Cộng")
                        {
                            int a = Convert.ToInt32(txtnhapa.Text);
                            int b = Convert.ToInt32(txtnhapb.Text);
                            int c = a + b;
                            txtketqua.Text = c.ToString();
                        }
                        if(comboBox1.Text=="Trừ")
                        {

                            int a = Convert.ToInt32(txtnhapa.Text);
                            int b = Convert.ToInt32(txtnhapb.Text);
                            int c = a - b;
                            txtketqua.Text = c.ToString();
                        }

                        if (comboBox1.Text == "Nhân")
                        {

                            int a = Convert.ToInt32(txtnhapa.Text);
                            int b = Convert.ToInt32(txtnhapb.Text);
                            int c = a * b;
                            txtketqua.Text = c.ToString();
                        }

                        if (comboBox1.Text == "Chia")
                        {

                            int a = Convert.ToInt32(txtnhapa.Text);
                            int b = Convert.ToInt32(txtnhapb.Text);
                            if (b == 0 && a != 0)
                            {
                                MessageBox.Show("Cannot divide by zero");
                            }
                            else
                            {

                                if (b == 0 && a == 0)
                                {
                                    MessageBox.Show("Result of function is underfined");
                                }
                                else
                                {
                                    int c = a / b;
                                    txtketqua.Text = c.ToString();
                                }
                            }
                            
                            
                        }

                    }
                }
            }
        }
    }
}
